package com.situ.mall.order.controller;

import com.situ.mall.common.entity.Category;
import com.situ.mall.common.entity.Product;
import com.situ.mall.common.service.IAttachmentService;
import com.situ.mall.common.service.ICategoryService;
import com.situ.mall.common.vo.IndexProductVO;
import com.situ.mall.common.service.IProductService;
import com.situ.mall.order.service.ICartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

//@RestController//代表所有的方法都是返回json数据，就不用加responseBody了  但是后面需要有返页面的
@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService productService;
    @Autowired
    private ICategoryService categoryService;
    @Autowired
    private IAttachmentService attachmentService;
    @Autowired
    private ICartService cartService;
    @GetMapping("/phone")
    @ResponseBody
    public List<IndexProductVO> phones(){
        return  productService.phones();
    }
    @GetMapping("/detail")
    public String detail(Integer id, Model model){
        Product p =productService.getById(id);
        model.addAttribute("product",p);
        //model.addAttribute("imgs",attachmentService.selectList(id,p.getName()));
        return "goods-details";
    }
    @ResponseBody
    @PostMapping("/cart")
    public void addToCart(Integer productId){
        cartService.addToCart(productId);
    }

}
